<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日期</title>
</head>
<body>
<div id='date'>
</div>
<script>
    if (typeof(EventSource) !== "undefined") {
        var eventSource = new EventSource("/index/getDate");

        eventSource.onmessage = function (event) {
            document.getElementById("date").innerHTML = event.data;
        }
        eventSource.addEventListener('error', function (event) {
            console.log("错误：" + event);
        });
        eventSource.addEventListener('open', function (event) {
            console.log("建立连接：" + event);
        });
    }
    else {
        document.getElementById("date").innerHTML = "抱歉，您的浏览器不支持 server-sent 事件 ...";
    }

</script>

</body>
</html>